package com.wanshu.service.impl;

import com.wanshu.dao.AddressDao;
import com.wanshu.entity.Address;
import com.wanshu.util.ResultUtil;

import java.util.List;

public class AddressServiceImpl {

    private AddressDao addressDao;

    public void setAddressDao(AddressDao addressDao) {
        this.addressDao = addressDao;
    }

    public String findById(Integer id){
        Address byId = addressDao.findById(id);
        if(byId != null){
            return ResultUtil.success("查询成功",byId);
        }else{
            return "未找到地址";
        }
    }

    public String delete(Integer id){
        Integer delete = addressDao.delete(id);
        if(delete > 0){
            return "删除地址成功!";
        }else{
            return "删除失败!";
        }
    }

    public String update(Address address){
        Integer update = addressDao.update(address);
        String msg = "修改失败!";
        if(update > 0){
           msg = "修改成功!";
        }
        return msg;
    }

    public List<Address> findAll(){
        return addressDao.findAll();
    }
}
